package cn.stylefeng.guns.modular.ha.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ha.entity.HaAgvTask;
import cn.stylefeng.guns.modular.ha.mapper.HaAgvTaskMapper;
import cn.stylefeng.guns.modular.ha.model.params.HaAgvTaskParam;
import cn.stylefeng.guns.modular.ha.model.result.HaAgvTaskResult;
import  cn.stylefeng.guns.modular.ha.service.HaAgvTaskService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 恒安接口请求数据 服务实现类
 * </p>
 *
 * @author 
 * @since 2025-08-29
 */
@Service
public class HaAgvTaskServiceImpl extends ServiceImpl<HaAgvTaskMapper, HaAgvTask> implements HaAgvTaskService {

    @Override
    public void add(HaAgvTaskParam param){
        HaAgvTask entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HaAgvTaskParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HaAgvTaskParam param){
        HaAgvTask oldEntity = getOldEntity(param);
        HaAgvTask newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HaAgvTaskResult findBySpec(HaAgvTaskParam param){
        return null;
    }

    @Override
    public List<HaAgvTaskResult> findListBySpec(HaAgvTaskParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(HaAgvTaskParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HaAgvTaskParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HaAgvTask getOldEntity(HaAgvTaskParam param) {
        return this.getById(getKey(param));
    }

    private HaAgvTask getEntity(HaAgvTaskParam param) {
        HaAgvTask entity = new HaAgvTask();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
